import java.util.Scanner;

/**
 * @author yu
 * @date 2025年04月17日 17:13
 */
public class _09_dp_09_01bags {
    public static int zeroOneBag(int n, int bagweight, int[] weight, int[] value) {
        // 创建一个动态规划数组 dp，初始值为 0
        int[] dp = new int[bagweight + 1];

        // 外层循环遍历每个类型的物品
        for (int i = 0; i < n; i++) {
            // 内层循环从 bagweight 空间逐渐减少到当前物品所占空间
            for (int j = bagweight; j >= weight[i]; j--) {
                // 考虑当前物品选择和不选择的情况，选择最大值
                dp[j] = Math.max(dp[j], dp[j - weight[i]] + value[i]);
            }
        }

        // 输出 dp[bagweight]，即在给定 bagweight 空间可以携带的物品的最大价值
        return dp[bagweight];
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int bagweight = scanner.nextInt();

        int[] weight = new int[n];
        int[] value = new int[n];

        for (int i = 0; i < n; ++i) {
            weight[i] = scanner.nextInt();
        }
        for (int j = 0; j < n; ++j) {
            value[j] = scanner.nextInt();
        }


        System.out.println(zeroOneBag(n, bagweight, weight, value));
        scanner.close();
    }
}